package com.yjhealth.libs.businessdemo.business;

import android.os.Bundle;
import android.support.v4.util.ArrayMap;
import android.view.View;
import android.widget.Button;

import com.yjhealth.libs.businessdemo.R;
import com.yjhealth.libs.businessdemo.net.HttpConstants;
import com.yjhealth.libs.commonlib.base.activity.BaseActivity;
import com.yjhealth.libs.commonlib.net.CommonPostManager;
import com.yjhealth.libs.commonlib.shapref.AccountSharpref;
import com.yjhealth.libs.core.core.activity.CoreActivity;
import com.yjhealth.libs.core.net.base.BaseObserver;
import com.yjhealth.libs.core.net.beans.NullResponse;
import com.yjhealth.libs.core.net.init.ConstantsHttp;

import java.util.ArrayList;

import io.reactivex.disposables.Disposable;

public class DemoNetActivity extends BaseActivity {
    private Button btnNet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.businessdemo_activity_demo_net);
        btnNet = findViewById(R.id.btnNet);
        btnNet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getData2();
                getData2();
            }
        });
    }

    @Override
    protected void onRefreshView() {
    }

    public void getData() {
        ArrayMap<String, String> head = new ArrayMap<>();
        head.put(ConstantsHttp.Head_Id, HttpConstants.CAS_HEALTH_NEW_SERVICE);
        head.put(ConstantsHttp.Head_Method, "listNewsForBigC");

        ArrayList body = new ArrayList();
        ArrayMap<String, Object> map = new ArrayMap<>();
        body.add(map);
        map.put("productPage", "00");
        map.put("areaId", "330100000000");
        map.put("tagId", "-1");
        map.put("page", 1);
        map.put("limit", 3);

        CommonPostManager.getInstance().post(activity, "*.jsonRequest", head, body, String.class, new BaseObserver<String>() {
            @Override
            public void onHandlePrePare(Disposable d) {
                showLoadingDialog();
            }

            @Override
            protected void onHandleSuccess(String value) {
            }

            @Override
            protected void onHandleError(String errorType, String msg) {

            }

            @Override
            protected void onHandleComplete() {
                dismissLoadingDialog();
            }
        });
    }

    public void getData2() {
        ArrayMap<String, String> head = new ArrayMap<>();
        head.put(ConstantsHttp.Head_Token, AccountSharpref.getInstance().getToken());
        head.put(ConstantsHttp.Head_Id, HttpConstants.CAS_IH_DOCTOR_CONSULT_SERVICE);
        head.put(ConstantsHttp.Head_Method, "queryAppOnlineProject");

        ArrayList body = new ArrayList();
        ArrayMap map = new ArrayMap();
        body.add(map);

        map.put("status", 2);

        CommonPostManager.getInstance().post(activity, head, body, NullResponse.class,
                new BaseObserver<NullResponse>() {
                    @Override
                    public void onHandlePrePare(Disposable d) {
                        showLoadingDialog();
                    }

                    @Override
                    protected void onHandleSuccess(NullResponse value) {
                    }

                    @Override
                    protected void onHandleError(String errorType, String msg) {
                    }

                    @Override
                    protected void onHandleComplete() {
                        dismissLoadingDialog();
                    }
                });
    }
}
